package fr.univ.surveyonline.dispatcher;

import java.io.IOException;
import java.util.Calendar;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import fr.univ.surveyonline.datastore.PMF;
import fr.univ.surveyonline.model.DateHelpers;
import fr.univ.surveyonline.model.Survey;

public class ContraintesServlet extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		RequestDispatcher rd = req.getRequestDispatcher("contraintes-choix.jsp");
		
		
		long surveyId = Long.valueOf(req.getParameter("survey"));		
		Survey survey = (Survey) PMF.getElementById(Survey.class, surveyId);
		String choice = req.getParameter("choix");
		
		if (choice.equals("publish")) {
			survey.setConstraintsVerified();
			rd = req.getRequestDispatcher("index.jsp");
		}
		
		if (choice.equals("delete")) {
			rd = req.getRequestDispatcher("/delete?survey=" + survey.getKey().getId());		
		}
		
		if (choice.equals("load")) {
			resp.sendRedirect("/load?survey=" + surveyId);
			return;
		}
		
		try {
			rd.forward(req, resp);
		} catch (ServletException e) {
			e.printStackTrace();
		}	
		
	}	
			
	
}
